var title = "中奖人员";
var config = {
    url_page: _dir + "Lucky_List.html",
    //url_add: _dir + "lotteryManage_add.html",
    title_page: title + "查询",
    title_list: title + "列表",
    //title_add: "添加" + title,
    //title_edit: "修改" + title,
    code_list: "/lotteryCase/public",
    //code_delete: "/lottery/del",
    //code_add: "/lotteryCase/add",
    //code_edit: "/lottery/update",
    //code_dataUpload: "/lottery/coverUpload",
    //code_imgUpload: "/lottery/upload",
    pagination_01: $("#page_01")
};
$(document).ready(function () {

    if (_page == "Lucky_List") {
        var pageNo = 1;
        setTitle_01(config['title_list'], config['title_page'], config['url_add']);
        setDefaultDate($("#startTime"),$("#endTime"))
        //加载事件
        var _trs, _pageSize, _pageCount;
        var setData = function (pIndex, pSize) {
            pIndex = pIndex || 1;
            pSize = pSize || 20;
            var pageSetBody = { "pageNo": pIndex, "pageSize": pSize };
            var sendObj = {
                "bookCode": $("#bookCode").val(),
                "bookName": $("#bookName").val(),
                "startTime": $("#startTime").val(),
                "endTime": $("#endTime").val(),
            };
            window.sessionStorage.setItem(_page+"data",JSON.stringify({
                'sendObj':sendObj,
                'pageSetBody':pageSetBody
            }));
            $.extend(sendObj,pageSetBody);
            _call(config['code_list'], sendObj, function (res) {
                _trs = "";
                if (!res.body || res.body.length == 0) {
                    _trs = "";
                    _pageSize = 1;
                    _pageCount = 1;
                    pageNo--
                    d_alert('警告','没有更多数据啦！','warning')
                }
                else {
                    _pageSize = res.body.pageSize;
                    _pageCount = res.body.count;
                    $.each(res.body, function (i, v) {
                        _trs = _trs + `<tr>
                            <td>${i+1}</td>
                            <td>${dataIsNull(v['bookCode'])}</td>
                            <td>${dataIsNull(v['bookName'])}</td>
                            <td>${dataIsNull(v['coverUrl'])}</td>
                            <td>${dataIsNull(v['downloadUrl'])}</td>
                            <td>${dataIsNull(v['bookDescribe'])}</td>
                            <td>${getTdOperate(6, config['url_add'], v.id, "id", v.id)}</td>
                        </tr>`;
                    });
                    setPageData(res.body);
                    //$("#table_01 tbody").html(_trs);
                }

                //绑定删除事件
                setDelete("id", config['code_delete']);

                //分页方法
            });
        };

        var loadingAll = function () {
            //初始化加载数据
            setData();
        }

        autoSearchByCookie(loadingAll);
        //查询方法
        loadingAll();
        $(".homePage").click(function(){
            pageNo = 1
            setData(pageNo)
        })
        $(".prevPage").click(function(){
            if(pageNo > 1){
                pageNo--
                setData(pageNo)
            }else{
                d_alert("警告",'已经到头啦！','warning')
            }
            
        })
        $(".nextPage").click(function(){
            pageNo++
            setData(pageNo)
        })
    }
});